package test;

import static org.junit.Assert.*;
import hospital.Hospital;
import main.*;
import movement.Location;

import org.junit.Before;
import org.junit.Test;

import unit.*;
import dispatch.DispatchCenter;
import emergency.*;

public class useCaseTestSelectHospital {
	FacadeDispatcher facade;
	FacadeUnit facade2;
	Location justALocation;
	
	DispatchCenter center;
	Garage garage;
	
	Emergency em1, em2, em3, em4;
	Unit u1;
	
	@Before
	public void setUp() throws Exception {
		String args[] = new String[1];
		args[0] = "environment.dat";
		World world = new World(args);
		facade = new FacadeDispatcher(world);
		facade2 = new FacadeUnit(world);
		
		center = facade.getDispatchCenter();
		garage = center.getGarage();
		justALocation = new Location(10,10,"NameDoesn'tMatter");
		
		em1 = new Fire(justALocation, Severity.NORMAL, center, Fire.Size.LOCAL, true, 1, 1);
	}
	
	@Test
	public void testSelectHospital(){
		facade.assignAllUnits(em1);
		
		u1 = em1.getUnits().get(1);

		Hospital h = center.getHospitals().get(0);
		
		center.getClock().advanceTime(200);
		
		facade2.assignHospital(u1, h);
		assertTrue(u1.getCurrentLocation().equals(em1.getLocation()));
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testSelectHospitalNoAmbulance(){
		facade.assignAllUnits(em1);
		
		u1 = em1.getUnits().get(1);
		
		Hospital h = center.getHospitals().get(0);
			
	    facade2.assignHospital(u1, h);
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testSelectHospitalUnitNotAssigned(){
		facade.assignAllUnits(em1);
		
		u1 = em1.getUnits().get(0);

		Hospital h = center.getHospitals().get(0);
		
	    facade2.assignHospital(u1, h);
		
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testSelectHospitalUnitNotAtEmergency(){
		facade.assignAllUnits(em1);
		
		u1 = em1.getUnits().get(0);

		Hospital h = center.getHospitals().get(0);
		facade2.assignHospital(u1, h);
	}
	
}
